package com.yc.tank;

import java.awt.Graphics;

/**
 * 爆炸效果
 * @author Administrator
 *
 */
public class Explode {

	private TankFrame tf;
	//爆炸位置
	private int x;
	private int y;
	private int frameStep = 0;//帧数（该爆炸效果由每次刷一次屏显示一张不同的图片完成）
	//爆炸是否还存活（还没炸毁）
	private boolean living = true;
	
	public Explode(TankFrame tf, int x, int y) {
		super();
		this.tf = tf;
		this.x = x;
		this.y = y;
	}
	
	public void paint(Graphics g) {
		g.drawImage(ResourceMgr.explodes[frameStep], x, y, null);
		if (frameStep == 1) {
			new Thread(() -> {
				Audio a = new Audio("audio/explode.wav");
				a.play();
			}).start();
			
		}
		frameStep++;
		if (frameStep == ResourceMgr.explodes.length) {
			frameStep = 0;//显示到最后一帧，再重置到第一帧
			living = false;//显示完一轮就可以销毁了
		}
	}
	
	/**
	 * 销毁
	 */
	public void die() {
		if (!living)
			tf.explodes.remove(this);
	}
}
